import UserData from '../UserData'

cc.Class({
    extends: cc.Component,

    properties: {
        chefStatusPrefab:{
            default:null,
            type:cc.Prefab,
        }
    },

    // LIFE-CYCLE CALLBACKS:

    // onLoad () {},

    start () {
        this.UserData = UserData
        this.resList = this.UserData.state.restaurantList
        this.getComponent()
        this.updateChefDataFromUserData()
    },
    updateChefDataFromUserData(){
        
        this.chefListData = []
        for(var i=0;i<this.resList.length;i++){
            if(this.resList[i]){
                if(this.resList[i].chef){                
                    for(var j;j<this.chefList.children;j++){//删除原有的所有主厨列表
                        this.chefList.children[j].destroy()
                    }
                    this.chefList.removeAllChildren()
                    
                    let chefCol = cc.instantiate(this.chefStatusPrefab)
                    this.chefListData.push(this.resList[i].chef)
                    let cp = chefCol.getComponent('ChefStatusPrefab')      
                    cp.loadChefData((this.resList[i].chef))                            
                    this.chefList.insertChild(chefCol)
                }
            }
        }
    },
    getComponent(){
        this.title = this.node.getChildByName('标题')
        this.chefList = this.node.getChildByName('滚动面板').getChildByName('view').getChildByName('Chef List')        
    }

    // update (dt) {},
});
